/*
 * FfmpegTsMuxer.h
 *
 *  Created on: 2016年8月24日
 *      Author: zhengboyuan
 */

#ifndef FFMPEGTSMUXER_H_
#define FFMPEGTSMUXER_H_

#include "TsMuxer.h"
#include "Ffmpeg.h"
#include "ByteBuffer.h"


namespace av
{

class FfmpegTsMuxer: public TsMuxer
{
public:
	FfmpegTsMuxer();
	virtual ~FfmpegTsMuxer();

	virtual int open(const UMediaFormat& fmt);

	virtual void close();

	virtual bool isOpen();

	virtual bool write(int type, uint8_t* data, int size, int64_t pts, int duration, int flags);

	virtual void setSink(TsMuxerSink sink);


protected:
    AVIOContext* createIOContext();
    static int ts_write_packet(void *opaque, uint8_t *buf, int buf_size);

    void writePacket(uint8_t *buf, int buf_size);

protected:
    TsMuxerSink	m_sink;

    AVFormatContext*	m_fmtCtx;
    int m_videoIndex;
    int m_audioIndex;

    UMediaFormat	m_format;

	ByteBuffer	m_buffer;

	int64_t m_pts;

};


} /* namespace av */

#endif /* FFMPEGTSMUXER_H_ */
